/*
* @Author: zlx
* @Date:   2018-02-27 10:08:24
* @Last Modified by:   Marte
* @Last Modified time: 2018-03-02 18:16:08
*/
//注册  分享注册 type=1;
//用户手机号
//	mark:客户端来源 0安卓 1IOS 2PC
//分享人手机号
var phone='',password='',loginManner=1,smsCode='';
var panter=/^1[34578][0-9]{9}$/;
var zc_type='member-register';//0分享注册、1会员注册
var rephone='';
var token='';
var time=60;
$(function(){
	//密码明文
	$(document).on('click','.eye',function(){
//		alert(1)
	    if($(this).find('img').attr("src") == "../../img/a_eye.png"){
	            $(".yzm .zz").prop("type","text");
	            $(this).find('img').attr("src","../../img/a_eye2.png");
	    }else{
	            $(".yzm .zz").prop("type","password");
	            $(this).find('img').attr("src","../../img/a_eye.png");
	    }
	});

	//有账号直接登陆
	$(document).on('click','.color',function(){
		window.location.href='login.html';
	})
		//qq登陆
	$('#qq').on('click',function(){
		window.location.href='../singlecenter/login_san.html?1';
	})
	//微信登陆
	$('#wx').on('click',function(){
//		window.location.href=rootdomain+'html/singlecenter/login_san.html?2';
		tips('暂不支持微信登录')
	})
	$(document).on('click','.send',function(){
		//获取验证码
		if($(this).attr('id')){
			type=$(this).attr('type');
			if(!panter.test($('.phone_n').val())){
				tips('请输入正确的手机号');
				return false;
			}else if(!$('.phone_n').val()){
				tips('请先填写手机号');
				return false;
			}else{
				$.post(apicom+'mobile/view/member/sendSms',{
					phone:$('.phone_n').val(),
					type:3//注册3
				},function(res){
					if(typeof res == "string"){
			            res=JSON.parse(res);
			        }
					setTimeout(function(){
						tips(res.msg)
					},1000);
					$('.send').attr('id','');
	                $('.send').text("重新获取" + "(" + (time) + ")");
	                var setId = setInterval(function() {
	                    if (time <= 0) {
	                        $('.send').attr('id','send');
	                        $('.send').text("发送验证码");
	                        clearInterval(setId);
	                        time=60;
	                    } else {
	                        time--;
	                        $('.send').text("重新获取" + "(" + (time) + ")");
	                    }
	                }, 1000);
				})
			}
		}
	})
	//登陆
	$(document).on('click','.login',function(){
		if($('#checkbox').prop('checked')){
			loginManner=Number($(this).attr('type'));
			phone=$('.phone_n').val();
			smsCode=$('.yan_m').val();
			password=$('.yan_pass').val();
			if(''==phone){
				tips('请先填写手机号');
				return false;
			}else if(!panter.test(phone)){
				tips('手机号码格式不正确');
				return false;
			}else if(''==smsCode){
				tips('请输入验证码');
				return false;
			}else if(password.length == 0 || password.length < 6 || 20 < password.length || password == ""){
				tips('请输入6-20位密码');
				return false;
			}else if (/\s/.test(password) || !(/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/.test(password)) ) {
	                tips("密码格式不正确");
	                return false;
	       }else{
				if(window.location.search){
					zc_type='invitation-register';
					reinfo=window.location.search.split('?')[1].split('&');
					rephone=reinfo[0].split('=')[1];
					token=reinfo[1].split('=')[1];
				}
				//注册
				$.post(apicom+'mobile/view/member/'+zc_type,{
					phone:phone,
					password:password,
					smsCode:smsCode,
					mark:mark,
					rephone:rephone,
					token:token
				},function(res){
					if(typeof res == "string"){
			            res=JSON.parse(res);
			        }
					tips(res.msg)
					if(1==res.code){
						tips(res.msg);
						setTimeout(function(){
							window.location.href="login_zm.html";
						},2000)

					}
				})
			}
		}else{
			tips('请先阅读协议')
			return false;
		}
	})
})
